package com.aaa.sys.controller;

import com.aaa.sys.entity.TabRoleMenu;
import com.aaa.sys.service.TabRoleMenuService;
import com.aaa.sys.service.impl.TabRoleMenuServiceImpl;

import com.aaa.util.LayData;
import com.aaa.util.PrintJsonData;

import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.annotation.*;
import java.io.IOException;
import java.util.List;

/**
 * (TabRoleMenu)表控制层
 *
 * @author makejava
 * @since 2023-04-25 11:16:05
 */


@WebServlet(name = "TabRoleMenuServlet", value = "/TabRoleMenuServlet")
public class TabRoleMenuServlet extends HttpServlet {

    private TabRoleMenuService tabRoleMenuService = new TabRoleMenuServiceImpl();

    @Override
    protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {

        // 
        String method = req.getParameter("method");
        if (method==null){

        }else if(method.equals("queryByRid")){
            queryByRid(req,resp);
            return;
        }else if(method.equals("query")){
            query(req,resp);
            return;
        }else if(method.equals("add")){
            add(req,resp);
            return;
        }else if(method.equals("upd")){
            upd(req,resp);
            return;
        }else if(method.equals("del")){
            del(req,resp);
            return;
        }

    }

    private void queryByRid(HttpServletRequest req, HttpServletResponse resp) {
        // 获取当前的角色的id的值
        String rid = req.getParameter("rid");
        List<Integer> mids=tabRoleMenuService.getMidByRid(rid);
        LayData success = LayData.success(mids);
        PrintJsonData.printData(resp,success);

    }


    private void del(HttpServletRequest req, HttpServletResponse resp) {
    }

    private void upd(HttpServletRequest req, HttpServletResponse resp) {
        // 接收前端的 rid   和 mids
        String rid = req.getParameter("rid");
        String mids = req.getParameter("mids");
        //
       boolean a= tabRoleMenuService.updTabRoleMenu(rid,mids);
        LayData success = LayData.success(a);
        PrintJsonData.printData(resp,success);
    }

    private void add(HttpServletRequest req, HttpServletResponse resp) {
    }

    private void query(HttpServletRequest req, HttpServletResponse resp) {

    }
}




